package com.hymjweb.demo.hymj.master_bill_manage.pull.detail.service;

import com.hymjweb.demo.framework.result.MIniUIGridResultMap;
import com.hymjweb.demo.framework.sys.BaseService;
import com.hymjweb.demo.framework.util.DataTypeUtil;
import com.hymjweb.demo.hymj.master_bill_manage.pull.detail.bean.BMasterBillPullDetailPojo;
import com.hymjweb.demo.hymj.master_bill_manage.pull.detail.mapper.BMasterBillPullDetailMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @BelongsProject: demo
 * @BelongsPackage: com.hymjweb.demo.hymj.master_bill_manage.pull.detail.service
 * @Author: luoge
 * @CreateTime: 2020-12-30 17:02
 * @Description:
 */


@Service
public class BMasterBillPullDetailService extends BaseService {

    @Autowired
    private BMasterBillPullDetailMapper bMasterBillPullDetailMapper;

    @Transactional(rollbackFor = {Exception.class})
    public int batchInsert(List<BMasterBillPullDetailPojo> bMasterBillPullDetailPojoList) throws Exception {
        if (bMasterBillPullDetailPojoList == null || bMasterBillPullDetailPojoList.isEmpty()) {
            throwException("批量插入拉货明细参数错误!");
        }
        return bMasterBillPullDetailMapper.batchInsert(bMasterBillPullDetailPojoList);
    }

    @Transactional(rollbackFor = {Exception.class})
    public int insert(BMasterBillPullDetailPojo bMasterBillPullDetailPojo) throws Exception {
        if (bMasterBillPullDetailPojo == null) {
            throwException("插入拉货明细参数错误!");
        }
        return bMasterBillPullDetailMapper.insert(bMasterBillPullDetailPojo);
    }

    @Transactional(rollbackFor = {Exception.class})
    public int update(BMasterBillPullDetailPojo bMasterBillPullDetailPojo) throws Exception {
        if (bMasterBillPullDetailPojo == null) {
            throwException("更新拉货明细参数错误!");
        }
        return bMasterBillPullDetailMapper.update(bMasterBillPullDetailPojo);
    }


    public Object queryPullDetailList(Map param) {
        this.setQueryCommParam(param);
        this.pageListInit(param);
        List<BMasterBillPullDetailPojo> list = queryPullDetailListNoPage(param);
        MIniUIGridResultMap resultMap = this.pageToGrid(list);
        return resultMap;
    }

    public List<BMasterBillPullDetailPojo> queryPullDetailListNoPage(Map param) {
        return bMasterBillPullDetailMapper.queryPullDetailList(param);
    }

    public Object getPageList(Map param) {
        // 设置公共查询参数,加上部门
        this.setQueryCommParam(param);
        this.pageListInit(param);
        List<Map<String, Object>> allList = bMasterBillPullDetailMapper.findAll(param);
        List<Map<String, Object>> convertList = DataTypeUtil.lineMapToHumpMap2(allList);
        MIniUIGridResultMap resultMap = this.pageToGrid(convertList);
        return resultMap;
    }


    /**
     * 获取改配的且没有完成的配载的列表
     *
     * @param param
     * @return
     */
    public List<BMasterBillPullDetailPojo> getReloadList(Map param) {
        return bMasterBillPullDetailMapper.getReloadList(param);
    }

    @Transactional(rollbackFor = {Exception.class})
    public int delete(String id) throws Exception {
        if (DataTypeUtil.isEmptyStr(id)) {
            throwException("删除拉货明细参数错误");
        }
        return bMasterBillPullDetailMapper.delete(id);
    }

    @Transactional(rollbackFor = {Exception.class})
    public int deleteByMasterBillId(String masterBillId) throws Exception {
        if (DataTypeUtil.isEmptyStr(masterBillId)) {
            throwException("删除拉货明细主单号参数错误");
        }
        return bMasterBillPullDetailMapper.deleteByMasterBillId(masterBillId);
    }
}
